/*
 * Copyright 1999-2018 Dist BI SZ Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { JSEncrypt } from 'jsencrypt';


/**
 * 用于对密码进行加密的密钥
 * @type {string} rsa公钥base64
 */
const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCAMVQ6xnNfDDLJ/FKpC40dhFxdKxg5dfC2Z97xloZ1s3Uq0oRjLOEmSm8rU80Yrk+asv+YsHGj5VutW2qdSgQbFY8kWVDhJth9GOPOIPVK8wxfspbP/+fWB1meVhpYtTHYWVv83X93peB4eBNJKlJyIPhwPcIzgXTvtJrgKXEVNwIDAQAB';

/**
 * 使用rsa公钥对明文进行加密处理
 * @param plain 明文
 * @returns {string} 密文
 */
const encrypt = plain => {
  let encrypt = new JSEncrypt();
  encrypt.setPublicKey(publicKey);
  return encrypt.encrypt(plain);
};

export default encrypt;
